package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Setter@Getter@NoArgsConstructor@AllArgsConstructor
public class Region extends BaseDomain{

    public static final int STATUS_COMMON = 0;//正常
    public static final int STATUS_RECOMMEND = 1;//推荐

    private String name;

    private Long parentId;

    private Integer status=STATUS_COMMON;


    public Map<String,Object> toMap(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",getId());
        map.put("text",getName());
        if (status==STATUS_RECOMMEND) {
            map.put("tags",new String[]{"推荐"});
        }
        map.put("lazyLoad",true);
        map.put("parentId",getParentId());
        map.put("json",getJsonString());
        return map;
    }

    public String getJsonString(){
        HashMap<Object, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",name);
        map.put("parentId",parentId);
        map.put("status",status);
        return JSONUtil.toJSONString(map);
    }
}